package sn.hn.demo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

public class ShopActivity extends Activity {
	public static Context mContext;
	public ShopView mShop;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		mShop = new ShopView(this);
		setContentView(mShop);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if(event.getAction() == MotionEvent.ACTION_DOWN)
		{
			if(event.getX() >= mShop.xPlay && event.getX() <= mShop.xPlay + mShop.mPlay.getWidth() &&  event.getY() >= mShop.yPlay && event.getY() <= mShop.yPlay + mShop.mPlay.getHeight())
			{
				mShop.isClickPlay = true;
				startActivity(new Intent(getBaseContext(), GameActivity.class));
				finish();
			}
			if(event.getX() >= mShop.xItem1 && event.getX() <= mShop.xItem1 + mShop.mItem1.getWidth() &&  event.getY() >= mShop.yItem1 && event.getY() <= mShop.yItem1 + mShop.mItem1.getHeight()){
				mShop.itemChoose = 0;
			}
			if(event.getX() >= mShop.xItem2 && event.getX() <= mShop.xItem2 + mShop.mItem2.getWidth() &&  event.getY() >= mShop.yItem2 && event.getY() <= mShop.yItem2 + mShop.mItem2.getHeight()){
				mShop.itemChoose = 1;
			}
			if(event.getX() >= mShop.xItem3 && event.getX() <= mShop.xItem3 + mShop.mItem3.getWidth() &&  event.getY() >= mShop.yItem2 && event.getY() <= mShop.yItem2 + mShop.mItem2.getHeight()){
				mShop.itemChoose = 2;
			}
			if(event.getX() >= mShop.xItem4 && event.getX() <= mShop.xItem4 + mShop.mItem4.getWidth() &&  event.getY() >= mShop.yItem4 && event.getY() <= mShop.yItem4 + mShop.mItem4.getHeight()){
				mShop.itemChoose = 3;
			}
		}
		return true;
	}
}
